package com.adun;

import com.adun.entity.Student;
import org.junit.Test;

import java.lang.reflect.Method;

/**
 * @author adun
 * @date 2021/2/25 23:48
 */
public class ReferenceTest {
    @Test
    public void refence() throws Exception {
        Class<?> stu = Class.forName("com.adun.entity.Student");
        //获取对象
        Object student = stu.newInstance();
        Student student1=(Student)student;
        student1.setId(1);
        student1.setName("wangwu");
        student1.setAge(18);
        student1.toString();

        //获取方法
        Method toString = stu.getDeclaredMethod("toString");
        toString.setAccessible(true);
        Object invoke = toString.invoke(student1);
        System.out.println(invoke);


    }

}
